var express = require("express");
var router = express.Router();
const Result = require("../utils/result");
const activityService = require("../services/activityService");

//获取活动列表
router.get('/list',async function(req,res){
    const {page,size,todayDate,type,city} = req.query;
    const {rows,count} = await activityService.list(page,size,todayDate,city);
    if(type == 1){
        const quickEndActs = rows.slice(0,3);
        res.json(Result.success({quickEndActs,activitys: rows,count}))
    }
    else{
        res.json(Result.success({activitys: rows, count}));
    }
})

//获取即将结束报名的活动
router.get('/quickEnd',async function(req,res){
    const { todayDate } = req.query;
    const quickEndActs = await activityService.quickEnd(todayDate);
    res.json(Result.success({quickEndActs}));
});


//获取活动详情
router.get('/detail',async function(req,res){
    const id = req.query.id;
    const activity = await activityService.getDetail(id);
    res.json(Result.success({activity}));
})

module.exports = router;